local skel = fk.CreateSkill {
  name = "rmt__qushou",
  tags = { Skill.Hidden }
}

local U = require "packages.utility.utility"

skel:addEffect(U.GeneralAppeared, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local get = room:askToChoosePlayers(player, {
      targets = room:getAlivePlayers(),
      min_num = 1,
      max_num = 1,
      prompt = "#rmt__qushou-cost",
      skill_name = skel.name,
      cancelable = true,
    })
    if #get > 0 then
      event:setCostData(self, {tos = get})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:setPlayerMark(to, "@rmt__qushou", player.general)
    player.room:setPlayerMark(to, "rmt__qushou", player.id)
  end,
})

skel:addEffect(fk.TurnEnd, {
  can_refresh = function(self, event, target, player, data)
    return player == target
  end,
  on_refresh = function(self, event, target, player, data)
    for _, p in ipairs(player.room:getAllPlayers()) do
      if p:getMark("rmt__qushou") == player.id then
        player.room:setPlayerMark(p, "@rmt__qushou", 0)
        player.room:setPlayerMark(p, "rmt__qushou", 0)
      end
    end
  end,
})

skel:addEffect("atkrange", {
  within_func = function (self, from, to)
    local mark = to:getMark("rmt__qushou")
    return mark ~= 0 and mark == from.id
  end,
})

Fk:loadTranslationTable{
  ["rmt__qushou"] = "取首",
  [":rmt__qushou"] = "隐匿技，你登场时，可指定一名角色视为在你攻击范围内直到你的回合结束。",

  ["@rmt__qushou"] = "取首",
  ["#rmt__qushou-cost"] = "取首：是否选择一名角色，使你的攻击范围包含其直至你回合结束？",

  ["$rmt__qushou1"] = "刃未沾红，袖不染尘，借你头颅祭残月。",
  ["$rmt__qushou2"] = "听，玉冠犹问：“何时月过帘门？",
}

return skel
